﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;

namespace OpenAdmin.Core.Models;

/// <summary>
/// 菜单表
/// </summary>
[Table("SysMenu")]
public class SysMenu : EntityBase<ApplicationDbContextLocator>, IEntityTypeConfigure<SysMenu>
{
    /// <summary>
    /// 菜单名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 父菜单id
    /// </summary>
    public int ParentId { get; set; }

    /// <summary>
    /// 菜单路由地址(菜单url)
    /// </summary>
    public string Route { get; set; }

    /// <summary>
    /// 图标
    /// </summary>
    public string Icon { get; set; }

    /// <summary>
    /// 是否激活
    /// </summary>
    public bool Enabled { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Sort { get; set; }

    public void Configure(EntityTypeBuilder<SysMenu> entityBuilder)
    {
        entityBuilder.Property(p => p.Name).HasMaxLength(50).IsRequired();
        entityBuilder.Property(p => p.Route).HasMaxLength(50).IsRequired();
        entityBuilder.Property(p => p.Icon).HasMaxLength(50).IsRequired();
    }
}
